package c_api

import (
	"gintest/models"
	"gintest/until"
	"github.com/gin-gonic/gin"
)
//接收数据
type GoodsRequest struct{
	Id int `json:"id"`
	StoreId int `json:"store_id"`
	Sort int `json:"sort"` 
	ParentId int `json:"parent_id"`
	Page uint64 `json:"page"` 
	PageSize uint64 `json:"pagesize"`  
}
func Goods_getlist(c *gin.Context){
	var data GoodsRequest
	if err:=c.ShouldBindJSON(&data) ;err!=nil {
		until.Fail(c,1,err.Error())
		return
	}
	//页面
	if data.Page<=0{
		data.Page=1
	}
	if data.PageSize<=0{
		data.PageSize=12
	}
	//商户ID
	if data.StoreId<=0{
		until.Fail(c,1,"商户号不能空")
		return
	}
	if data.Sort>2 || data.Sort<0{
		until.Fail(c,1,"排序方式错误")
		return
	}
	list:=models.GetGoodsListOfStore(data.Page,data.PageSize,"",data.StoreId,2,data.Sort,data.ParentId)
	until.Success(c,list)
}
func Goods_getinfo(c *gin.Context){
	var data GoodsRequest
	if err:=c.ShouldBindJSON(&data) ;err!=nil {
		until.Fail(c,1,err.Error())
		return
	}
	if data.Id<=0{
		until.Fail(c,1,"商品编号不能空")
		return
	}
	info:=models.GetGoodsById(data.Id)
	if info.Id!=0{
		until.Success(c,info)
	}else{
		until.Success(c,nil)
	}
}

func Goods_getclass(c *gin.Context){
	var data GoodsRequest
	if err:=c.ShouldBindJSON(&data) ;err!=nil {
		until.Fail(c,1,err.Error())
		return
	}
	if data.StoreId<=0{
		until.Fail(c,1,"商户号不能空")
		return
	}
	list:=models.GetStoreCustomClassListOfPid(data.StoreId,data.ParentId)
	until.Success(c,list)
}